#ifndef __FILE_H_
#define __FILE_H_

#include <globalDecl.h>
#include <page.h>
#include <predicate.h>

class File {

	Page *m_pCurrentPage; // this pointer always holds the non flat version the page that m_iCurrPageNum points to in the physical binary file.

	char *m_cScratchPad;
	char *m_cReadPad;
 
	bool m_bPageDirty; // TRUE means needs to be written to the HD. NOT IN USE, BUT MIGHT BE NEEDED LATER.

	char* m_cBinaryFName; // rcvd from the user
	char* m_cTextFName; // rcvd from the user
	char* m_cSchName; // rcvd from the user
	char* m_cRelName; // rcvd from the user

	int m_iFd; // saves the file descriptor...
	int m_iCurrPageNum; // used in nextrec function
	int m_iCurrRec;  // for next rec function
	
public:

        // returns the current length of the file, in pages
        int GetLength ();

        // opens the given file; the first parameter tells whether or not to
        // create the file.  If the parameter is zero, a new file is created
        // the file; if notNew is zero, then the file is created and any other
        // file located at that location is erased.  Otherwise, the file is
        // simply opened
        void Open (int notNew, char *fName);

        // moves the record "pointer" in the file to the first record on
        // the specified page in the file
        void MovePointer (int whichPage);

        // gets the next record in the file; returns a 0 if there are no more
        // records and a 1 otherwise
        int NextRec (Record &getMe);

        // adds a new record to the very end of the file; this also updates
	// the current "pointer" so that it is pointing just past the end of the file
        void Append (Record &addMe);

        // allows someone to explicitly get a specified page from the file
        void GetPage (Page &putItHere, int whichPage);

        // allows someone to explicitly write a specified page to the file;
        // if the write is past the end of the file, all of the new pages that
        // are before the page to be written are zeroed out
        void AddPage (Page &addMe, int whichPage);

        // closes the file and returns the file length (in number of pages)
        int Close ();

        File ();
        ~File ();
	
	void setParams(char*,char*,char*,char*);
	int txt2bin();
	void ApplyPredicate(char* _cSchFile,char* _cRelSchema,char* _cPredName,char* _cBinName);
};

#endif

